<?php
namespace app\admin\controller;

use think\Controller;
use think\Db;

class Report extends Controller
{
    public function index()
    {
        $report = Db::name("report r")->join("user u", "r.uid=u.userId")
            ->join("reporttype rt", "r.reporttype=rt.rtid")
            ->field("rid,rcontent,r.uid,pic,sNumber,name,teleNumber")
            ->where("reporttype", 1)
            ->where("rstatus",0)->select();
        $reporttype = Db::name("reporttype")->select();
        $this->assign("report", $report);
        $this->assign("reporttype", $reporttype);
        return $this->fetch();
    }
    public function del($id)
    {
        $data = [
            "rid"=>$id,
            "rstatus"=>1
        ];
        $rs = Db::name("report")->update($data);
        if($rs){
            $this->redirect('index');
        }else{
            $this->redirect('index');
        }
    }
    public function change($rid)
    {
        $report = Db::name("report r")->join("user u", "r.uid=u.userId")
            ->join("reporttype rt", "r.reporttype=rt.rtid")
            ->field("rid,rcontent,r.uid,pic,sNumber,name,teleNumber")
            ->where("reporttype", $rid)
            ->where("rstatus",0)->select();
        $reporttype = Db::name("reporttype")->select();
        $currenttype = Db::name("reporttype")->where("rtid", $rid)->find();
        $this->assign("report", $report);
        $this->assign("reporttype", $reporttype);
        $this->assign("currenttype", $currenttype);
        return $this->fetch();
    }
    public function changedone($rid)
    {
        $report = Db::name("report r")->join("user u", "r.uid=u.userId")
            ->join("reporttype rt", "r.reporttype=rt.rtid")
            ->field("rid,rcontent,r.uid,pic,sNumber,name,teleNumber")
            ->where("reporttype", $rid)
            ->where("rstatus",1)->select();
        $reporttype = Db::name("reporttype")->select();
        $currenttype = Db::name("reporttype")->where("rtid", $rid)->find();
        $this->assign("report", $report);
        $this->assign("reporttype", $reporttype);
        $this->assign("currenttype", $currenttype);
        return $this->fetch();
    }
    public function done(){
        $report = Db::name("report r")->join("user u", "r.uid=u.userId")
        ->join("reporttype rt", "r.reporttype=rt.rtid")
        ->field("rid,rcontent,r.uid,pic,sNumber,name,teleNumber")
        ->where("reporttype", 1)
        ->where("rstatus",1)->select();
        $reporttype = Db::name("reporttype")->select();
        $this->assign("report", $report);
        $this->assign("reporttype", $reporttype);
        return $this->fetch();
    }
}
